//
//  QVerifyWebViewController.m
//  QWeiboSDK4iOSDemo
//
//  Created   on 11-1-14.
//   
//

#import "QVerifyWebViewController.h"
#import "BaseManager.h"
#import "ManagerAdapter.h"
#import "RenRenManager.h"



@implementation QVerifyWebViewController

@synthesize homeViewController = _homeViewController;


// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}

- (id)initWithHomeViewController:(StarterController *) homeController {
    self = [super init];
    if (self){
        self.homeViewController = homeController;
    }
    return self;
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{

    NSLog(@"QVerifyWebViewController.viewDidLoad....");
    [super viewDidLoad];
    mWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
    mWebView.delegate = self;
    [self.view addSubview:mWebView];
    
#warning should extract to a function?
    [[ManagerAdapter instance] getManager:self.homeViewController.type];

    BaseManager *manager = [[ManagerAdapter instance] getManager:self.homeViewController.type];
    
    [mWebView loadRequest:[manager getURLRequest]];
    
}




- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
#warning mWebView need release here?
    [_homeViewController release];
    [super dealloc];
}



#pragma mark -
#pragma mark UIWebViewDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{    

    
	ManagerAdapter *managerAdapter =[ManagerAdapter instance];
     id manager = [managerAdapter getManager:self.homeViewController.type];
    
#warning need handle all navigation type?
   
    if (NO==[manager VerifyRequest:request]) {
        [self.view removeFromSuperview];
        [self.homeViewController prepareData];
        [self.homeViewController updateUI];
        return NO;
    }
    
    return YES;

}
@end
